import java.io.*;
import java.util.Scanner;

public class Caesar
 {
    public static void main(String[] args) {
        System.out.println("输入“1”加密；输入“2”解密");
        Scanner c = new Scanner(System.in);
        int b = c.nextInt();
        if (b == 1) {
            System.out.print("请输入秘钥：");
            Scanner s = new Scanner(System.in);
            int a = s.nextInt();
            C(a);
        } else if (b == 2) {
            System.out.print("请输入秘钥：");
            Scanner s = new Scanner(System.in);
            int a = s.nextInt();
            B(a);
        }
    }
    public static void C(int n) {
            char b[];
            BufferedReader br2 = new BufferedReader(new
                    InputStreamReader(System.in));
            System.out.println("请输入一段明文：");
            String str2 = br2.readLine();
            b = str2.toCharArray();
            System.out.println("密文为:");
            int k = n;
            for (int i = 0; i < str2.length(); i++) {
                char ch = (char) ((b[i] - 'a' + k) % 26 + 'a');
                System.out.print(ch);
            }
            System.out.println("密钥K=" + k);
            System.out.println(e.getMessage());
        }
    }

    public static void B(int m) {
            char b[];
            BufferedReader br2=new BufferedReader(new
                    InputStreamReader(System.in));
            System.out.println("请输入一段密文：");
            String str2=br2.readLine();
            b=str2.toCharArray();
            System.out.println("明文为:");
            int k=m;
            for(int i=0;i<str2.length();i++)
            {
                char ch=(char)((b[i]-'a'-k)%26+'a');
                System.out.print(ch);
            }
            System.out.println("密钥K="+k);
            System.out.println(e.getMessage());
        }
}
}
